package com.cvmars.jianyou.module.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.cvmars.jianyou.R;
import com.cvmars.jianyou.api.api.Api;
import com.cvmars.jianyou.api.api.HttpUtils;
import com.cvmars.jianyou.api.api.SimpleSubscriber;
import com.cvmars.jianyou.api.model.HttpResult;
import com.cvmars.jianyou.config.MyConfig;
import com.cvmars.jianyou.model.UserModel;
import com.cvmars.jianyou.module.base.BaseActivity;
import com.cvmars.jianyou.ui.CircleImageView;
import com.cvmars.jianyou.utils.ImageUtils;
import com.cvmars.jianyou.utils.ToastUtils;
import com.orhanobut.hawk.Hawk;

import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
//
//import top.limuyang2.alipaylibrary.AliPayObserver;
//import top.limuyang2.alipaylibrary.FastAliPay;
//import top.limuyang2.basepaylibrary.PayResource;


public class XiangQingActivity extends BaseActivity {

    @BindView(R.id.txt_dating)
    TextView txtDating;
    @BindView(R.id.iv_avator)
    CircleImageView ivAvator;
    @BindView(R.id.txt_name)
    TextView txtName;
    @BindView(R.id.iv_sex)
    ImageView ivSex;
    @BindView(R.id.txt_address)
    TextView txtAddress;
    @BindView(R.id.txt_age)
    TextView txtAge;
    @BindView(R.id.txt_address_company)
    TextView txtAddressCompany;
    @BindView(R.id.txt_intro)
    TextView txtIntro;
    @BindView(R.id.ed_content)
    EditText edContent;
    @BindView(R.id.parent_layout)
    LinearLayout parentLayout;
    @BindView(R.id.txt_subject)
    Button txtSubject;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_xiang_qing);
        ButterKnife.bind(this);

        UserModel model = Hawk.get(MyConfig.SP_CACHE_USERMODEL);

        ImageUtils.loadImage(this, model.avatar_url, ivAvator);

        txtName.setText(model.name);
        txtAddress.setText(model.address_home);
        txtAge.setText(model.age);
        txtIntro.setText(model.intro);
        edContent.setText(model.expect_desc);
        txtAddressCompany.setText(model.address_company);
        ivSex.setImageResource(model.gender == 1 ? R.drawable.ic_male : R.drawable.ic_women);

    }


    @OnClick({R.id.txt_dating, R.id.txt_subject})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.txt_dating:

                break;
            case R.id.txt_subject:

                String s = edContent.getText().toString();
                if (TextUtils.isEmpty(s)) {

                    ToastUtils.show("内容不能为空");
                    return;
                }
                HashMap<String, Object> map = new HashMap<>();
                map.put("expect_desc", s);
                map.put("is_rut", true);
                onUpdateInfo(map);
                break;
        }
    }


    private void onUpdateInfo(Map<String, Object> map) {
        HttpUtils.getInstance().toSubscribe(Api.getInstance().UpdataInfoUseInfos(map)
                , new SimpleSubscriber<HttpResult<UserModel>>() {
                    @Override
                    protected void _onNext(HttpResult<UserModel> o) {


                        setResult(RESULT_OK,getIntent());
                        finish();
                    }

                    @Override
                    protected void _onError(String message) {

                    }
                });
    }
}
